package main

import (
	"fmt"
	"sort"
)

func main() {
	g := []int{1, 2}
	s := []int{1, 2, 3}
	a := findContentChildren1(g, s)
	fmt.Print(a)
}

func findContentChildren(g []int, s []int) int {
	if len(s) < 1 {
		return 0
	}
	sort.Ints(g)
	sort.Ints(s)
	pre := len(g) - 1
	pro := len(s) - 1
	count := 0
	for {
		if g[pre] <= s[pro] {
			count += 1
			pre -= 1
			pro -= 1
		} else {
			pre -= 1
		}
		if pre < 0 || pro < 0 {
			break
		}
	}
	return count
}

func findContentChildren1(g []int, s []int) (res int) {
	sort.Ints(g)
	sort.Ints(s)
	for pre, pro := len(g)-1, len(s)-1; pre >= 0 && pro >= 0; pre -= 1 {
		if g[pre] <= s[pro] {
			res += 1
			pro -= 1
		}
	}
	return
}
